<template>
  <el-select
    v-model="sys_code_value_"
    placeholder="请选择"
    @change="selectChange"
  >
    <el-option
      v-for="item in options"
      :key="item.sys_code"
      :label="item.sys_code_name"
      :value="item.sys_code"
    >
    </el-option>
  </el-select>
</template>

<script>
import * as Request from "../../general/request";

export default {
  name: "sys_code",
  created() {
    this.sys_code_get();
  },
  props: {
    sys_code_type: String,
    sys_code_value: String,
  },
  setup(props, { emit }) {
    const selectChange = (val) => {
      emit("childClick", val);
    };
    return {
      selectChange,
      props,
    };
  },
  watch: {
    sys_code_value: function (newVal) {
      // console.log(newVal);
      this.sys_code_value_ = newVal;
    },
  },
  data() {
    return {
      options: [],
      sys_code_value_: "",
    };
  },
  methods: {
    async sys_code_get() {
      const response = await Request.GET("/background/home/sys_code", {
        sys_code_type: this.props.sys_code_type,
      });
      if (response && response.data) {
        var return_data = response.data;
        if (return_data.success) {
          this.options = return_data.data;
          // this.$message.success(return_data.msg)
        } else {
          this.$message.error(return_data.msg);
        }
      }
    },
  },
};
</script>

<style scoped></style>
